﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CvModel;
using System.Data.Entity.Migrations;
using System.Data.SqlClient;
using System.Data;

namespace DAL
{
    public class WorkApplicationsDB
    {
        private static CvModelContainer _context = new CvModelContainer();

        //CREATE
        public static int CreateWorkApplication(WorkApplication workApplication)
        {
            try
            {
                var query = _context.WorkApplications.Add(workApplication);
                return _context.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }
        //READ
        public static WorkApplication GetWorkApplication(int workApplicationId)
        {
            try
            {
                return _context.WorkApplications.Where(w => w.WorkApplicationId == workApplicationId).ToList().First();
            }
            catch (Exception)
            {

                throw;
            }
        }
        //UPDATE
        public static int UpdateWorkApplication(WorkApplication workApplication)
        {
            try
            {
                _context.WorkApplications.AddOrUpdate(workApplication);
                return _context.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }
        //DELETE
        public static int DeleteWorkApplication(int workApplicationId)
        {
            try
            {
                var query =
                    (from w in _context.WorkApplications
                     where w.WorkApplicationId == workApplicationId
                     select w).Single();

                _context.WorkApplications.Remove(query);

                return _context.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
